package com.business.weixin.service;

import java.util.List;
import java.util.Arrays;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.business.system.common.base.BaseService;
import com.business.system.common.support.Convert;
import com.business.weixin.mapper.auto.WechatAccessTokenMapper;
import com.business.weixin.model.auto.WechatAccessToken;
import com.business.weixin.model.auto.WechatAccessTokenExample;
import com.business.system.model.custom.Tablepar;
import com.business.system.util.SnowflakeIdWorker;

/**
 *  WechatAccessTokenService
 * @Title: WechatAccessTokenService.java 
 * @Package com.business.weixin.service 
 * @author LuJingyuan_自动生成
 * @email 674326842@qq.com
 * @date 2020-11-23 15:55:20  
 **/
@Service
public class WechatAccessTokenService implements BaseService<WechatAccessToken, WechatAccessTokenExample>{
	@Autowired
	private WechatAccessTokenMapper wechatAccessTokenMapper;
	
      	   	      	      	      	      	
	/**
	 * 分页查询
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	 public PageInfo<WechatAccessToken> list(Tablepar tablepar,String name){
	        WechatAccessTokenExample testExample=new WechatAccessTokenExample();
	        testExample.setOrderByClause("id ASC");
	        if(name!=null&&!"".equals(name)){
	        	testExample.createCriteria().andAccessTokenLike("%"+name+"%");
	        }

	        PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
	        List<WechatAccessToken> list= wechatAccessTokenMapper.selectByExample(testExample);
	        PageInfo<WechatAccessToken> pageInfo = new PageInfo<WechatAccessToken>(list);
	        return  pageInfo;
	 }

	@Override
	public int deleteByPrimaryKey(String ids) {
				
			List<String> lista=Convert.toListStrArray(ids);
			WechatAccessTokenExample example=new WechatAccessTokenExample();
			example.createCriteria().andIdIn(lista);
			return wechatAccessTokenMapper.deleteByExample(example);
			
				
	}
	
	
	@Override
	public WechatAccessToken selectByPrimaryKey(String id) {
				
			return wechatAccessTokenMapper.selectByPrimaryKey(id);
				
	}

	
	@Override
	public int updateByPrimaryKeySelective(WechatAccessToken record) {
		return wechatAccessTokenMapper.updateByPrimaryKeySelective(record);
	}
	
	
	/**
	 * 添加
	 */
	@Override
	public int insertSelective(WechatAccessToken record) {
				
		//添加雪花主键id
		record.setId(SnowflakeIdWorker.getUUID());
			
				
		return wechatAccessTokenMapper.insertSelective(record);
	}
	
	
	@Override
	public int updateByExampleSelective(WechatAccessToken record, WechatAccessTokenExample example) {
		
		return wechatAccessTokenMapper.updateByExampleSelective(record, example);
	}

	
	@Override
	public int updateByExample(WechatAccessToken record, WechatAccessTokenExample example) {
		
		return wechatAccessTokenMapper.updateByExample(record, example);
	}

	@Override
	public List<WechatAccessToken> selectByExample(WechatAccessTokenExample example) {
		
		return wechatAccessTokenMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(WechatAccessTokenExample example) {
		
		return wechatAccessTokenMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(WechatAccessTokenExample example) {
		
		return wechatAccessTokenMapper.deleteByExample(example);
	}
	
	/**
	 * 检查name
	 * @param wechatAccessToken
	 * @return
	 */
	public int checkNameUnique(WechatAccessToken wechatAccessToken){
		WechatAccessTokenExample example=new WechatAccessTokenExample();
		example.createCriteria().andAccessTokenEqualTo(wechatAccessToken.getAccessToken());
		List<WechatAccessToken> list=wechatAccessTokenMapper.selectByExample(example);
		return list.size();
	}

	/**
	 * 根据map查询list
	 * @param map
	 * @return
	 */
	public List<WechatAccessToken> selectByMap(Map<String,String> map){
		return wechatAccessTokenMapper.selectByMap(map);
	}


}
